<?php
/**
 * Parcl
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://parcl.com/license
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@parcl.com so we can send you a copy immediately.
 *
 * @category parcl
 * @package parcl-core
 * @copyright Copyright (c) 2006-2011 Mikael Knutsson (http://mikn.me)
 * @license http://parcl.com/license New BSD License
 * 
 * @todo Replace Parcl::Headers() with this class.
 */

class Headers implements ISingleton {
	private static $instance = null;
	private $headers = null;

	public static function GetInstance() {
		if(is_null(self::$instance)) {
			self::$instance = new Headers();
		}
		return self::$instance;
	}

	private function __construct() {
		$this->headers = new ArrayObject();
	}

	private function areHeadersSent() {
		if(headers_sent()) {
			throw new GeneralException('Tried setting headers after they were sent.');
			return true;
		}
		return false;
	}

	public function SetContentType($contentType) {
		$this->areHeadersSent();
		$this->headers['Content-Type: '] = $contentType;
	}
	public function GetContentType() {
		return $this->headers['Content-Type: '];
	}

	public function Send() {
		/*foreach($this->headers as $key => $header) {
			header(is_numeric($key) ? $key . $header : $header);
		}*/
		header('Content-Type: text/html');
	}
}